﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public class mainPage
    {
        private shopnetEntities _model;
        public Cart cart{get;set;}
        public mainPage() {
            _model = new shopnetEntities();
            cart = new Cart(_model);
        }
        public void index(){
            var categories = new Category(_model);
            
        }
        public void select_category(int id) {
            var categories = new Category(_model);
            var products = id!=0 ? _model.products.Where(prod => prod.categoryID == id) : null;
        }
        public void get_price_list() {
            var categories = _model.categories;
            Dictionary<int, List<product>> price_list = new Dictionary<int, List<product>>();
            var tmp = new List<int>();
            foreach (var cat in categories) {
                tmp.Add(cat.categoryID);
            }
            foreach (var i in tmp) {
                price_list.Add(i,_model.products.Where(p => p.categoryID == i).ToList());
            }
        }
        public void aux_page(int index) {
            this.index(); //get generic elements
            var aux = _model.aux_pages.SingleOrDefault(i=> i.id == index);
            Console.WriteLine(aux.content);
        }
        public void aux_page(string index) {
            this.index();
            var aux = _model.aux_pages.SingleOrDefault(i=> i.name == index.ToLower());
            Console.WriteLine(aux.content);
        }
        public void search(string str_srch) {
            var res = _model.products.Where(p => p.name.Contains(str_srch) || p.description.Contains(str_srch) || p.brief_description.Contains(str_srch) );
        }
    }
}
